package com.wsmall.fenxiao.goods.web;

import com.wsmall.fenxiao.goods.dal.mapper.GoodsInfoDOMapperExt;
import com.wsmall.fenxiao.goods.dal.pojo.GoodsInfoDO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RefreshScope
@RestController
public class GoodsController {

  @Value("${name}")
  private String name;
  @Autowired
  private GoodsInfoDOMapperExt goodsInfoDOMapperExt;

  @ResponseBody
  @RequestMapping("/goods/save")
  public Object saveGood(String name, Double price) {
    log.debug("添加商品数据,name=" + name + "price=" + price);
    GoodsInfoDO goodsInfoDO = new GoodsInfoDO();
    goodsInfoDO.setName(name);
    goodsInfoDO.setPrice(price);
    goodsInfoDOMapperExt.insert(goodsInfoDO);
    return Boolean.TRUE;
  }

  @ResponseBody
  @RequestMapping("goods")
  public Object hello(String goods) {
    log.info("获取配置中心goods-dev.yml配置文件中name属性的值!");
    return goods + ":" + name;
  }

}
